/**
 * @author 雷明浩
 * @date 2025/6/3 16:15
 */
public class Search {
    // newcoder 二分查找-II
    // https://www.nowcoder.com/practice/d3df40bd23594118b57554129cadf47b?tpId=295&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3FquestionJobId%3D10%26subTabName%3Donline_coding_page
    public int search (int[] nums, int target) {
        // write code here
        if (nums.length == 0) {
            return -1;
        }
        int left = 0, right = nums.length-1;
        while (left < right) {
            int mid = left +(right-left) / 2;
            if (nums[mid] < target) {
                left = mid + 1;
            }else {
                right = mid;
            }
        }
        return nums[left] == target ? left : -1;
    }
}